<?php
// +----------------------------------------------------------------------
// |
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2019 http://www.thinkcmf.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 小夏 < 449134904@qq.com>
// +----------------------------------------------------------------------
namespace app\admin\controller;

use cmf\controller\AdminBaseController;
use think\Db;

class ProtectController extends AdminBaseController
{
    public function initialize()
    {
        parent::initialize();
    }

    public function protect()
    {
    //        订单
        $orders = Db::name('orders')->find();
        $this->assign($orders);

        $results = Db::name('protect')->alias('p')
            ->join('protect_payment pp','pp.order_id=p.order_id')
            ->select();
        //echo Db::name('protect')->getLastSql();
        $this->assign("protect_payment", $results);
        return $this->fetch();
    }

    public function add_post()
    {
        $data = array(
            'order_id' => 1,
            'dealer' => $_POST['dealer'],
            'sex' => $_POST['sex'],
            'tel' => $_POST['tel'],
            'relation' => $_POST['relation'],
            'card_ytpe' => $_POST['card_ytpe'],
            'cart_num' => $_POST['cart_num'],
            'address' => $_POST['address'],
        );

        Db::name('protect')->insert($data);
        $this->protect_payment_add();

        $this->success("添加成功！", url("Protect/protect"));
    }


    public function protect_payment_add()
    {
        $album = array(
            'order_id' => 1,
            'price' => $_POST['price'],
            'duration' => $_POST['duration'],
            'reduce' => $_POST['reduce'],
            'total' => $_POST['total'],
            'dealers' => $_POST['dealers'],
        );
        $pay_time = $_POST['pay_time'];
        $album['pay_time'] = strtotime($pay_time);
        Db::name('protect_payment')->insert($album);
    }


}